Ext.ns('cn.hls.web.action.biz.shipper');
var shipperForm = cn.hls.web.action.biz.shipper.shipperForm,photoWin,photoPanel,win,panel,oldImgId,safetyCardPhotoWin,safetyCardPhotoPanel,safetycard_oldId,safetyCardIndex=0;
(function($){
	
	  //图片显示
    viewPhoto=function(imgId){
  	  if(!photoPanel||oldImgId!=imgId){
  		  oldImgId=imgId;
  		  createPhotodPanel(imgId);
  		  photoWin=undefined;
  	  }
  	  if(!photoWin){
  		  photoWin = new ExtWin({
  			width : 400,
				height : 480,
				title : '<div class="panelTitleCss">个人照片</div>',
  		  	items:[photoPanel],
  		  	buttons : [{
					text : '关闭',
					iconCls : 'deleteIcon',
					handler : function() {
						photoWin.hide();
					}
				}]
  		  });
  	  }
  	  photoWin.show();
  	 $("#"+imgId).show();
    },
    createPhotodPanel=function(id){
  	  photoPanel=new Ext.Panel({
  		  layout : 'fit',
  		  items: [{
		        	padding : 5,
					bodyStyle:'overflow-y:auto;overflow-x:hidden;',
					contentEl : 'sp_content_'+id
		        }]
  	  });
  	  return photoPanel;
    },
    openSafetyCardView=function(imgId,filePath){
      safetyCardIndex=0;
  	  var files=filePath.split(',')
   	 if(!safetyCardPhotoPanel||safetycard_oldId!=imgId){
   		 safetycard_oldId=imgId;
		  createSafeCardPhotoPanel(imgId);
		  safetyCardPhotoWin=undefined;
    	  }
    	  if(!safetyCardPhotoWin){
    		 safetyCardPhotoWin = new ExtWin({
    			width : 700,
  				height : 650,
  				title : '<div class="panelTitleCss">应急方案</div>',
    		  	items:[safetyCardPhotoPanel],
    		  	buttons : [
    		  	         {text:'上一张',
    	    		  	     id:'btn_pre',
    	    		  	     iconCls:'x-tbar-page-prev',
    	    		  	     handler:function(){
    	    		  	    	 if(safetyCardIndex>0){
    	    		  	    		safetyCardIndex--;
    	    		  	    		 var extStart = files[safetyCardIndex].lastIndexOf(".");
    					    	     var ext = files[safetyCardIndex].substring(extStart, files[safetyCardIndex].length).toUpperCase();
    					    	     if (ext != ".PDF"&&ext != ".DOC"&&ext != ".DOCX"){//显示图片
    					    	    	 $("#safetyCard_photo_img_"+imgId).attr('src',cfg.cxt+'/upload/'+files[safetyCardIndex]);
    					    	    	 $("#safetyCard_photo_img_"+imgId).show();
    					    	    	 $("#safetyCard_attach_sp_"+imgId).hide();
    					    	     }else{
    					    	    	 $("#safetyCard_attach_sp_"+imgId).html('<a target="_blank" href="'+cfg.cxt+'/upload/'+files[safetyCardIndex]+'">附件：'+files[safetyCardIndex]+'</a>');
    					    	    	 $("#safetyCard_photo_img_"+imgId).attr('src',cfg.cxt+'/upload/'+files[safetyCardIndex]);
    					    	    	 $("#safetyCard_photo_img_"+imgId).hide();
    					    	    	 $("#safetyCard_attach_sp_"+imgId).show();
    					    	     }
    	    		  	    	 }
    	    		  	     }
    	    		  	    },{
    	    		  	    	text:'下一张',
    	    		  	    	iconCls:'x-tbar-page-next',
    	    		  	    	id:'btn_next',
    	    		  	    	handler:function(){
    	    		  	    		 if(safetyCardIndex<(files.length-1)){
    	    		  	    			safetyCardIndex++;
    	        		  	    		var extStart = files[safetyCardIndex].lastIndexOf(".");
    	    				    	     var ext = files[safetyCardIndex].substring(extStart, files[safetyCardIndex].length).toUpperCase();
    	    				    	     if (ext != ".PDF"&&ext != ".DOC"&&ext != ".DOCX"){//显示图片
    	    				    	    	 $("#safetyCard_photo_img_"+imgId).attr('src',cfg.cxt+'/upload/'+files[safetyCardIndex]);
    	    				    	    	 $("#safetyCard_photo_img_"+imgId).show();
    	    				    	    	 $("#safetyCard_attach_sp_"+imgId).hide();
    	    				    	     }else{
    	    				    	    	 $("#safetyCard_attach_sp_"+imgId).html('<a target="_blank" href="'+cfg.cxt+'/upload/'+files[safetyCardIndex]+'">附件：'+files[safetyCardIndex]+'</a>');
    	    				    	    	 $("#safetyCard_photo_img_"+imgId).hide();
    	    				    	    	 $("#safetyCard_attach_sp_"+imgId).show();
    	    				    	     }
    	        		  	    	 }
    	    		  	    	}
    	    		  	    },{
		  					text : '关闭',
		  					iconCls : 'deleteIcon',
		  					handler : function() {
		  						$("#safetyCard_photo_img_"+imgId).hide();
								$("#safetyCard_attach_sp_"+imgId).hide();
		  						safetyCardPhotoWin.hide();
		  					}
		    		  	 }]
    		  });
    	  }
    	  if(files.length==1){
    		  Ext.getCmp('btn_pre').setVisible(false);//设置不可见
    		  Ext.getCmp('btn_next').setVisible(false);//设置不可见
    	  }else{
    		  Ext.getCmp('btn_pre').setVisible(true);//设置不可见
    		  Ext.getCmp('btn_next').setVisible(true);//设置不可见
    	  }
    	  var extStart = files[0].lastIndexOf(".");
 	      var ext = files[0].substring(extStart, files[0].length).toUpperCase();
 	     if (ext != ".PDF"&&ext != ".DOC"&&ext != ".DOCX"){//显示图片
	    	  $("#safetyCard_photo_img_"+imgId).attr('src',cfg.cxt+'/upload/'+files[0]);
	    	  $("#safetyCard_photo_img_"+imgId).show();
	    	  $("#safetyCard_attach_sp_"+imgId).hide();
 	     }else{
 	    	$("#safetyCard_attach_sp_"+imgId).html('<a target="_blank" href="'+cfg.cxt+'/upload/'+files[safetyCardIndex]+'">附件：'+files[safetyCardIndex]+'</a>');
	    	 $("#safetyCard_photo_img_"+imgId).hide();
	    	 $("#safetyCard_attach_sp_"+imgId).show();
 	     }
    	 safetyCardPhotoWin.show();
   },
   createSafeCardPhotoPanel=function(id){
   	safetyCardPhotoPanel=new Ext.Panel({
   		  layout : 'fit',
   		  items: [{
 		        	padding : 5,
 					bodyStyle:'overflow-y:auto;overflow-x:hidden;',
 					contentEl : 'sp_content_'+id
 		        }]
   	  });
   	  return safetyCardPhotoPanel;
     }
})(jQuery)

